<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "https://raw.githubusercontent.com/rbatis/rbatis/master/rbatis-codegen/mybatis-3-mapper.dtd">
<mapper>
    <select id="get_dept_by_user_id">
        `select sd.* from sys_dept sd inner join sys_user su on su.dept_id = sd.dept_id`
        <where>
            `su.user_id = #{user_id}`
        </where>
    </select>
    <select id="get_dept_list">
        `select * from sys_dept`
        <where>
            1 = 1
            <if test="dept_name != ''">
                ` and dept_name = #{dept_name}`
            </if>
            <if test="status != ''">
                ` and status = #{status}`
            </if>
        </where>
    </select>
    <select id="get_dept_list_exclude_id">
        `select * from sys_dept`
        <where>
            1 = 1
            <if test="dept_id != ''">
                ` and dept_id != #{dept_id}`
            </if>
        </where>
    </select>
    <select id="get_dept_tree_by_id">
        select T2.* from (
        select @R as rid,
        (select @R := parent_id from sys_dept where dept_id = rid) as parent_id,
        @L := @L+1 as LVL
        from (select @R := #{dept_id},@L :=0) vars,
        sys_dept h where @R>=0)T1
        inner join sys_dept T2 on T1.rid = T2.dept_id
        order by T1.LVL desc
    </select>
    <select id="get_dept_by_id">
        `select * from sys_dept`
        <where>
            `dept_id = #{dept_id}`
        </where>
    </select>
    <delete id="del_dept_by_id">
        `delete from sys_dept`
        <where>
            `dept_id = ( ${dept_id} )`
        </where>
    </delete>
</mapper>